const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import _config from "./config";
import reqTools from "../utils/reqTools";

// mock 数据
var mock = new MockAdapter(mockAxios);

mock.onGet('/communityCost/getAll').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/communityHouseCost',config.params).then(res => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});


mock.onDelete('/communityCost/delete').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete('/api/communityHouseCost/'+config.id).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onPut('/communityCost/updateHasGive').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/communityHouseCost', config.data, 
   ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//生成物管费
mock.onPost('/communityCost/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/communityHouseCost',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

export default mockAxios;
